import os
import sys

from threading import Thread, Event


class Monitor(Thread):
	"""Base monitor class with threading support"""

	def __init__(self, window, config_file):
		Thread.__init__(self)

		self._window = window
		self._config_file = Monitor.get_config_filename(config_file)
		self._thread_active = Event()
		self._visible = False

	@classmethod
	def get_config_filename(self, base_name):
		"""Get full path to config file"""
		return os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'config', base_name)

	def run(self):
		"""Thread loop method"""
		self._thread_active.set()

	def show(self):
		"""Shop monitor and its windows"""
		self._visible = True

	def hide(self):
		"""Hide monitor and its windows"""
		self._visible = False

	def notify_terminate(self):
		"""Notification from main thread about application termination"""
		self._thread_active.clear()
